home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9161 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1021 b 

  1. Path: news.lpr.carel.fi!usenet
  2. From: Ari Lukumies <aril@cmt.lpr.mail.carel.fi>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: hex to dec function?
  5. Date: Thu, 07 Mar 1996 15:45:41 +0200
  6. Organization: Carelcomp Forest
  7. Message-ID: <313EE885.4511@cmt.lpr.mail.carel.fi>
  8. References: <4gdh1b$bg@mailhost.mwmicro.com> <4hl8mk$1er@info.uah.edu>
  9. NNTP-Posting-Host: renoir.cclahti.carel.fi
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (WinNT; I)
  14.  
  15. Greg Bacon wrote:
  16.  
  17. [snip]
  18.  
  19. > Assuming you have a string representing some hexadecimal quantity and
  20. > you want to print its equivalent decimal value:
  21. > #include <stdio.h>
  22. > #include <stdlib.h>
  23. > /*
  24. >  :
  25. >  :
  26. >  */
  27. > {
  28. >    char *strHexVal = "20";  /* 32 auf decimal */
  29. >    (void) printf("%d\n", strtol(strHexVal, (char **) NULL, 10));
  30. > [snip]
  31.  
  32. Just a quick sidenote: if you use strtol() in a printf call, use the correct format 
  33. string, also: "%ld\n".
  34.  
  35. Later,
  36.  AriL
  37. -- 
  38. All my opinions are mine and mine alone.
  39.